


// 
//size = 5
//
//0 1 2 3 4
//5 6 * * *
//
//当r=2 w=6时
//6 - 2 =  4 < size 可以推最后一次
//此时r还需要读 2 3 4 5 6
//
//
//
//
//w=22

#include <vector>

#include <iostream>

#include <string>

using namespace std;



struct CbsString {
    const char* data_;
    int size_;

};



//template <typename T>
void* operator new(size_t t) {

    cout << "malloc" << "\n";
    return malloc(t);
}

template<typename T>
struct VectorSized {
    vector<T> data;
    string ticker;
    size_t write_idx;
    int size;
    VectorSized(const int& p_size = 0) {
        write_idx = 0;
        size = p_size == 0 ? 5 : p_size;
        data.resize(size);
    }

    //数据溢出情况要怎么处理  即write_idx 不能++了， 但是仍然要推数据，对vector扩容
    void push(const T& t) {
        if (write_idx < size) {
            data[write_idx++] = t;
        }
        else {
            realloc();
            data[write_idx++] = t;
        }
    }
    // realloc时 元素的移动顺序为 readidx -> size 和  0 ->readidx-1     ,再置writeidx = size, readidx = 0,
    void realloc() {
        cout << "re";
        vector<T> temp;
        temp.resize(size);
        for (int i = 0; i < size; i++) {
            temp[i] = data[i];
        }

        data.resize(2 * size);

        for (int j = 0; j < size; j++) {
            data[j] = temp[j];
        }
        size = 2 * size;
    }
};

struct MyStruct
{
    int d;
};

int main() {

    string test = "sssssss";       

}

